home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / thsfs.tgz / thsfs.tar / thsfs / inode.c < prev    next >
C/C++ Source or Header  |  1994-10-04  |  6KB  |  267 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  *    ths  Filesystem                  04.10.94      V1.1    *
  4.  *                                                           *
  5.  *    Thomas Scheuermann     ths@ai-lab.fh-furtwangen.de     *
  6.  *                                                           *
  7.  *************************************************************/
  8.  
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/stat.h>
  15. #include <linux/mm.h>
  16. #include <linux/locks.h>
  17. #include <linux/fs.h>
  18. #include <linux/malloc.h>
  19.  
  20. #include <asm/system.h>
  21. #include <asm/segment.h>
  22. #include <asm/bitops.h>
  23.  
  24. #include "ths.h"
  25. #include "ths_i.h"
  26.  
  27.  
  28. static struct file_operations ths_file_ops =
  29. {
  30.     NULL,        /* lseek - default */
  31.     ths_read,        /* read */
  32.     NULL,        /* write */
  33.     NULL,        /* readdir - bad */
  34.     NULL,        /* select - default */
  35.     NULL,        /* ioctl - default */
  36.     NULL,        /* mmap */
  37.     NULL,        /* no special open is needed */
  38.     NULL,        /* release */
  39.     NULL        /* fsync */
  40. };
  41.  
  42. static struct file_operations ths_dir_ops =
  43. {
  44.     NULL,        /* lseek - default */
  45.     ths_dir_read,        /* read */
  46.     NULL,        /* write */
  47.     ths_readdir,        /* readdir - bad */
  48.     NULL,        /* select - default */
  49.     NULL,        /* ioctl - default */
  50.     NULL,        /* mmap */
  51.     NULL,        /* no special open is needed */
  52.     NULL,        /* release */
  53.     NULL        /* fsync */
  54. };
  55.  
  56. struct inode_operations ths_dir_inode_ops =
  57. {
  58.     &ths_dir_ops,  /* default directory file-ops */
  59.     NULL,            /* create */
  60.     ths_lookup,            /* lookup */
  61.     NULL,            /* link */
  62.     NULL,            /* unlink */
  63.     NULL,            /* symlink */
  64.     NULL,            /* mkdir */
  65.     NULL,            /* rmdir */
  66.     NULL,            /* mknod */
  67.     NULL,            /* rename */
  68.     NULL,            /* readlink */
  69.     NULL,            /* follow_link */
  70.     NULL,            /* bmap */
  71.     NULL,            /* truncate */
  72.     NULL            /* permission */
  73. };
  74.  
  75. struct inode_operations ths_file_inode_ops =
  76. {
  77.     &ths_file_ops,  /* default directory file-ops */
  78.     NULL,            /* create */
  79.     NULL,            /* lookup */
  80.     NULL,            /* link */
  81.     NULL,            /* unlink */
  82.     NULL,            /* symlink */
  83.     NULL,            /* mkdir */
  84.     NULL,            /* rmdir */
  85.     NULL,            /* mknod */
  86.     NULL,            /* rename */
  87.     NULL,            /* readlink */
  88.     NULL,            /* follow_link */
  89.     NULL,            /* bmap */
  90.     NULL,            /* truncate */
  91.     NULL            /* permission */
  92. };
  93.  
  94. void ths_read_inode(struct inode *in)
  95. {
  96.     struct ths_buffer tbf,tbf2;
  97.     struct ths_inode_info *ths_inode;
  98.     struct ths_sb_info *ths_sb;
  99.     struct ths_dir *dir=NULL;
  100.     int i,tmp,test;
  101.     unsigned char *data=NULL;
  102.  
  103. #ifdef DEBUG
  104.     printk("read_inode : %ld\n",in->i_ino);
  105. #endif
  106.  
  107.     ths_inode = (struct ths_inode_info *)&(in->u.generic_ip);
  108.     ths_sb = (struct ths_sb_info *)in->i_sb->u.generic_sbp;
  109.  
  110.  
  111.     in->i_uid = 0;
  112.     in->i_gid = 0;
  113.     in->i_nlink = 1;
  114.     in->i_blocks = 0;
  115.     in->i_blksize = 0;
  116.     in->i_mode |= S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
  117.  
  118.     if(in->i_ino==THS_ROOT_INODE)
  119.     {
  120. /*
  121.  * Root-Inode
  122.  */
  123.         in->i_mode = in->i_mode | S_IFDIR;
  124.         in->i_op = &ths_dir_inode_ops;
  125.         in->i_atime = 0;
  126.         in->i_mtime = 0;
  127.         in->i_ctime = 0;
  128.         ths_inode->Cluster = (short)ths_sb->RootStart;
  129.         strcpy(ths_inode->name,"Rootdir");
  130.         for(i=0;i<ths_sb->RootMaxEintraege*32;)
  131.         {
  132.             if(!(i&0x1ff))
  133.             {
  134.                 if(ths_read_sektor(in->i_sb,(ths_sb->RootStart+(i>>9)), &tbf2))
  135.                 {
  136.                     printk("Fehler\n");
  137.                     return;
  138.                 }
  139.                 data = tbf2.data[0];
  140.             }
  141.             if(data[i&0x1ff]==0x00)
  142.             {
  143.                 ths_free_sektor(&tbf2);
  144.                 break;
  145.             }
  146.             i+=32;
  147.             if(!(i&0x1ff))
  148.                 ths_free_sektor(&tbf2);
  149.         }
  150.         in->i_size=i;
  151. #ifdef DEBUG
  152.         printk("Groesse Root: %d\n",i);
  153. #endif
  154.     }
  155.     else
  156.     {
  157. /*
  158.  * Andere Inode
  159.  */
  160.         test=0;
  161.         if((in->i_ino>>4) < ths_sb->DatenStart)
  162.         {
  163.             test=1;
  164.         }
  165.         if(test)
  166.         {
  167.             if(ths_read_sektor(in->i_sb,in->i_ino>>4,&tbf))
  168.             {
  169.                 printk("Fehler\n");
  170.                 return;
  171.             }
  172.         }
  173.         else
  174.         {
  175.             if(ths_read_cluster(in->i_sb,((in->i_ino>>4)-ths_sb->DatenStart)/ths_sb->SektorenProCluster,0,&tbf))
  176.             {
  177.                 printk("Fehler\n");
  178.                 return;
  179.             }
  180.         }
  181. /*
  182.  * Position des Eintrags im Sektor berechnen
  183.  */
  184.         data = tbf.data[((in->i_ino>>4)-ths_sb->DatenStart)&(tbf.sektore-1)];
  185.         tmp = in->i_ino & 0x0f;
  186.         tmp *= 32;
  187.         dir = (struct ths_dir *)&data[tmp];
  188. #ifdef DEBUG
  189.         printk("offset : %d , %ld\n",tmp,((in->i_ino>>4)-ths_sb->DatenStart)&(tbf.sektore-1));
  190. #endif
  191. /*
  192.  * Informationen eintragen
  193.  */
  194.         if(dir->attribut & 0x10)
  195.         {
  196.             in->i_mode |= S_IFDIR;
  197.             in->i_op = &ths_dir_inode_ops;
  198.             for(i=0;i<1000*32;)
  199.             {
  200.                 if(!(i&0x1ff))
  201.                 {
  202.                     if(!((i/512)%ths_sb->SektorenProCluster))
  203.                     {
  204.                         if(ths_read_cluster(in->i_sb,CHS(dir->cluster),(long)i,&tbf2))
  205.                         {
  206.                             printk("Fehler\n");
  207.                             return;
  208.                         }
  209.                     }
  210.                     data = tbf2.data[(i/512)%tbf2.sektore];
  211.                 }
  212.                 if(data[i&0x1ff]==0x00)
  213.                 {
  214.                     ths_free_cluster(&tbf2);
  215.                     break;
  216.                 }
  217.                 i+=32;
  218.                 if(!((i&0x1ff)||((i/512)%ths_sb->SektorenProCluster)))
  219.                     ths_free_cluster(&tbf2);
  220.             }
  221.             in->i_size=i;
  222. #ifdef DEBUG
  223.             printk("Groesse Sub: %d\n",i);
  224. #endif
  225.         }
  226.         else
  227.         {
  228.             in->i_mode |= S_IFREG;
  229.             in->i_op = &ths_file_inode_ops;
  230.             in->i_size = CHL(dir->laenge);
  231.         }
  232.  
  233.         for(i=0;i<8;i++)
  234.             ths_inode->name[i]=dir->name[i];
  235.         ths_inode->name[i++]=0x20;
  236.         for(;i<12;i++)
  237.             ths_inode->name[i]=dir->endung[i-9];
  238.         ths_inode->name[i]='\0';
  239.  
  240.  
  241.         in->i_atime = time_ms2u(CHS(dir->datum),CHS(dir->zeit));
  242.         in->i_mtime = in->i_atime;
  243.         in->i_ctime = in->i_atime;
  244.  
  245.         ths_inode->Cluster = CHS(dir->cluster);
  246.  
  247.         if(test)
  248.             ths_free_sektor(&tbf);
  249.         else
  250.             ths_free_cluster(&tbf);
  251.     }
  252. #ifdef DEBUG
  253.     printk("Name : %s ",ths_inode->name);
  254.     if(in->i_ino != THS_ROOT_INODE)
  255.         printk("Attribut : 0x%x ",dir->attribut);
  256.     printk("Cl : 0x%x ",ths_inode->Cluster);
  257.     printk("L : 0x%lx\n",in->i_size);
  258. #endif
  259. }
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.